package org.example.Day12;

import org.junit.Test;

import java.lang.reflect.Constructor;
import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;

public class Test2 {
    @Test
    public void testGetConstructors() throws Exception {
        //得到类的Class对象
        Class c = Cat.class;

        Field fName = c.getDeclaredField("name");
        System.out.println(fName.getName()+"--->"+fName.getType());

        Field fAge = c.getDeclaredField("age");
        System.out.println(fAge.getName()+"--->"+fAge.getType());

        Cat cat = new Cat();
        fName.setAccessible(true);
        fName.set(cat,"咖啡猫");
        System.out.println(cat);

        String name = (String)fName.get(cat);
        System.out.println(name);

    }

}
